﻿@inject IHttpService _httpService
@inject IPopupService PopupService
@inject IEventService _eventService

<MDCard>
    <DataTableCard TModel="StaffInforTableModel" Headers="_headers" ApiUrl="@(_baseUrl)" ShowAddButton="false" Title="@($"{_name}列表")" @ref="dataTableCard">
        <ItemColContent>
            @if (context.Header.Value == "actions")
            {
                <MIcon Color="info"
                       Class="mr-2"
                       OnClick="()=>LookItem(context.Item)">@IconType.Look.ToIconString()</MIcon>
            }
            else
            {
                @context.Value
            }
        </ItemColContent>
    </DataTableCard>
</MDCard>




@code {
    private bool _editDialog;
    private long _editedItemId;
    private bool _detailDialog;

    private string _baseUrl = "api/tables/ListStaffs";
    private string _name = "Staff";

    private List<DataTableHeader<StaffInforTableModel>> _headers = new List<DataTableHeader<StaffInforTableModel>>
    {
        new ()
          {
            Text= "Id",
            Align= DataTableHeaderAlign.Start,
            Value= nameof(StaffInforTableModel.RealId)
          },
          new (){ Text= "游戏名称", Value= nameof(StaffInforTableModel.GameName)},
          new (){ Text= "分组", Value= nameof(StaffInforTableModel.Subcategory)},
          new (){ Text= "官方职位", Value= nameof(StaffInforTableModel.PositionOfficial)},
          new (){ Text= "官方称呼", Value= nameof(StaffInforTableModel.NicknameOfficial)},
          new (){ Text= "通用职位", Value= nameof(StaffInforTableModel.PositionGeneral)},
          new (){ Text= "隶属组织", Value= nameof(StaffInforTableModel.SubordinateOrganization)},
          new (){ Text= "操作", Value= "actions",Sortable=false }
    };

    DataTableCard<StaffInforTableModel> dataTableCard;

    [CascadingParameter]
    public ErrorHandler ErrorHandler { get; set; }

    public async Task LookItem(StaffInforTableModel model)
    {
        await _eventService.OpenNewPage("https://www.cngal.org/entries/index/" + model.RealId);
    }
}
